import frappe
import requests
from frappe import _

@frappe.whitelist()
def get_mes_data(filters=None):
    """获取MES质量数据的工具函数"""
    try:
        api_url = "http://117.161.137.2:24013/prod-api/mes/qc/ipqc/erpQueryList"
        response = requests.get(api_url, timeout=30)
        response.raise_for_status()
        
        data = response.json()
        
        if data.get('rows'):
            return data['rows']
        else:
            return []
    except Exception as e:
        frappe.log_error(f"获取MES数据失败: {str(e)}", "MES Data Fetch")
        return []
